<?php

class CheckNameAction extends CAction
{
    public function run()
    {
        if(!isset($_POST['name']))
            throw new CHttpException(400,'the request is invalid');

        $user=new User;
        $user->name=$_POST['name'];
        
        $succ=false;
        if(!$user->validate(array('name'))) {
            $error=$user->getError('name');
        }
        else {
            if(User::loadObjectByName($user->name, array('id'))){
                $error='该用户名已存在';
            }
            else {
                $succ=true;        
            }
        }
        
        $this->controller->layout=false;
        $this->controller->renderText($succ?'true':'false');
    }
}
  
?>
